home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
SPACE 2
/
SPACE - Library 2 - Volume 1.iso
/
apps
/
102
/
examples
/
st_alarm.c
< prev
next >
Wrap
C/C++ Source or Header
|
1987-01-25
|
9KB
|
178 lines
/* program accessory "Ein Wecker im ST" - "An ST_Alarm"
extracted from ST Computer,Nr 10 ,pp. 36-38 ,1986;
pub. in Germany in German. Works with MWC 12 Oct86-CJP with correct sp.! */
/* tested under the new GDOS V.1.1 14 December, 1986 - CJP - failed to work */
/* changed to Raster Coordinates and in[11] -OK- 14 December, 1986 - CJP - */
/* notes on build of accessory ; ANALOG Nov'86 p.77 - MarkWilliams C - ATARI-ST
/ Creating a desk accessory requires the following steps ( not given in the
/ MW C manual): save crtsg.o in a safe directory(the normal GEM startup code)
/ assemble the following code to use in it's place,
/ name it crtsg.o and put into the lib directory;
/ after this compile with the -VGEM for a proper desk accessory.
/ The MWC version of "accstart.s"--
.shri /shared instructions
.globl main_ /label of C program start
start:
lea estack,sp /set top of stack
jsr main_ /begin program
clr.w -(sp) /code == terminate process
trap $1 /GEMDOS call
.bssd
ustack: .blkw 1024 /space for stack == 1K
estack: .blkl 1 /top of stack */
/* program as partly translated from German, correct for use in MWC and GDOS */
/* The original text was ALCYON-C, one change for GST and one for Megamax-C */
#include <osbind.h> /* system constants */
#include <gemdefs.h> /* GEM-definition */
#include <obdefs.h> /* object definition */
#define UEIN 4 /* label line */
#define WAUS 9 /* time line */
#define WZEIT 10 /* alarm line */
#define ANZAHL 12 /* set alarm line */
char *strings[] = { "ST Computer Clock Control","HOUR:","ON","OFF","ALARM:",
"ON","OFF","____","WAKETIME: __:__","9999","OK" } ;
TEDINFO txtinfo = { 7L, 8L, 9L, 3, 6, 0, 0x1180, 0x0, 255, 5, 16 } ;
OBJECT objekte[] = {
-1, 1, 11, G_BOX, NONE, OUTLINED, 0x21111L, 0,0, 29, 9,
2, -1, -1, G_BUTTON, NONE, OUTLINED, 0x0L, 2,1, 25, 1,
6, 3, 5, G_BOX, NONE, NORMAL, 0x1100L, 2,3, 25, 1,
4, -1, -1, G_STRING, NONE, NORMAL, 0x1L, 0,0, 6, 1,
5, -1, -1, G_BUTTON, 0x11, NORMAL, 0X2L, 13,0, 5, 1,
2, -1, -1, G_BUTTON, 0x11, NORMAL, 0x3L, 20,0, 5, 1,
10, 7, 9, G_BOX, NONE, NORMAL, 0x1100L, 2,5, 25, 1,
8, -1, -1, G_STRING, NONE, NORMAL, 0x4L, 0,0, 7, 1,
9, -1, -1, G_BUTTON, 0X11, NORMAL, 0x5L, 13,0, 5, 1,
6, -1, -1, G_BUTTON, 0X11, NORMAL, 0x6L, 20,0, 5, 1,
11, -1, -1, G_FTEXT, EDITABLE, NORMAL, 0x0L, 2,7, 15, 1,
0, -1, -1, G_BUTTON, 0X27, NORMAL, 0xAL, 20,7, 7, 1
} ;
int contrl[12],intin[128],intout[128],ptsin[128],ptsout[128];
extern int gl_apid; /* AES processor call */
/* bei,i.e.for, GST: extern short gl_apid; */
#define RC_COORDS 2
main()
{ /* bei ALCYON C: register long zeit; */
register unsigned long zeit; /* bei MWC: time variable */
static char uhr[] = "00/00/00 00:00" ; /* static hour */
static char warte[] = { 0xff, 20, 0xff,0 };
register char zr;
/* Bei Megamax: int tast,anz,weck,ereig,zh,vn,h,aus[57]; */
short tast,anz,weck,ereig,zh,vn,h,ii,in[11],aus_0,aus_1,aus[57];
/* To fix up for generality with GDOS in 1987, I add in[11] ,i.e.,work_in[11]*/
/* initialize in[0] thru in[9],use in[10] --- then set up raster coordinates*/
GRECT fm ;
appl_init();
anz = 0 ; /* start with 0 attitude */
for(h = 0; h<ANZAHL; h++) /* object coordinates */
{
rsrc_obfix(objekte,h); /* compute */
switch(objekte[h].ob_type) /* object type */
{
case G_STRING: /* object specification */
case G_BUTTON: /* to set correctly */
objekte[h].ob_spec = strings[objekte[h].ob_spec];
break; /* finished..... */
case G_FTEXT: /* text format */
objekte[h].ob_spec = &txtinfo;
}
}
txtinfo.te_ptext = strings[txtinfo.te_ptext] ; /* TEDINFO */
txtinfo.te_ptmplt = strings[txtinfo.te_ptmplt]; /* " */
txtinfo.te_pvalid = strings[txtinfo.te_pvalid]; /* to set */
form_center(objekte,&fm.g_x,&fm.g_y,&fm.g_w,&fm.g_h); /* center */
objc_change(objekte,UEIN,0,fm.g_x,fm.g_y,fm.g_w,fm.g_h,SELECTED,0);
objc_change(objekte,WAUS,0,fm.g_x,fm.g_y,fm.g_w,fm.g_h,SELECTED,0);
vn = graf_handle(&h,&zh,&h,&h) ; zh -= 2 ;
for( ii = 0 ; ii < 10 ; ++ ii ) in [ii] = 1 ; /* init in array */
in[10] = RC_COORDS ;
v_opnvwk(in,&vn,aus);
aus_0 = aus [0] >> 5 ;
aus_1 = aus [1] ;
aus_1 = aus_1 - ( aus_1 >> 7 ) ;
vst_color(vn,1);
menu_register(gl_apid," ST Alarm Control " ) ;
while(1)
{
if(anz || weck)
{
zeit = Gettime()>>5;
zr = ((char)zeit) & 0x3f;
uhr[12] = zr / 10 + '0';
uhr[13] = zr % 10 + '0';
zeit >>=6;
zr = zeit &0x1f; /* next 5 bits */
uhr[ 9] = zr / 10 + '0';
uhr[10] = zr % 10 + '0';
}
if(anz)
{
zeit >>= 5; /* day count */
zr = ((char)zeit) & 0x1f;
uhr[ 3] = zr / 10 + '0';
uhr[ 4] = zr % 10 + '0'; /* American day */
/* uhr[ 0] = zr / 10 + '0'; uhr[ 1] = zr % 10 + '0'; tag German style*/
zeit >>= 5; /* month count */
zr = ((char)zeit) & 0xf;
uhr[ 0] = zr / 10 + '0';
uhr[ 1] = zr % 10 + '0'; /* American month */
/* uhr[ 3] = zr / 10 + '0'; uhr[ 4] = zr % 10 + '0'; mon.German style */
zr = ((char)((zeit >> 4) + 80L) % 100) & 0x7f;
uhr[ 6] = zr / 10 + '0'; /* year count */
uhr[ 7] = zr % 10 + '0';
/* mono or color(lowrex or medrez,with or without GDOS) with TOS in ROM */
v_gtext( vn , aus_0 , aus_1 , uhr ) ;
/* where aus[0] = x_max and aus[1] = y_max: reform/lower left corner loc.*/
/* lower right-corner-upper right */
}
if(weck) /* that is: IF WAKE-UP CALL ? */
if (uhr[ 9] == strings[7][0] && uhr[10] == strings[7][1] &&
uhr[12] == strings[7][2] && uhr[13] == strings[7][3])
{
Cconout(7);
while(Dosound(-1L));
Dosound(warte); /* 1. */
while (Dosound(-1L));
Cconout(7); /* 2. pipetone */
form_alert(1, /* In English */
"[1][ Your ST servant says:| Now is the Time!][ OK ]");
}
ereig = evnt_multi(MU_TIMER | MU_MESAG, /* */
0,0,0,0,0,0,0,0,0,0,0,0,0,aus,10000,0,&h,&h,&h,&h,&h,&h);
if((ereig & MU_MESAG) && (*aus == AC_OPEN)) /* Memu action?*/
{
form_dial(FMD_START,fm.g_x,fm.g_y,fm.g_w,fm.g_h,
fm.g_x,fm.g_y,fm.g_w,fm.g_h);
objc_draw(objekte,ROOT,MAX_DEPTH,
fm.g_x,fm.g_y,fm.g_w,fm.g_h);
tast = form_do(objekte,WZEIT);
form_dial(FMD_FINISH,fm.g_x,fm.g_y,fm.g_w,fm.g_h,
fm.g_x,fm.g_y,fm.g_w,fm.g_h);
objc_change(objekte,tast,0,
fm.g_x,fm.g_y,fm.g_w,fm.g_h,NORMAL,0);
if(objekte[UEIN].ob_state) anz = 1;
else anz = 0;
if(objekte[WAUS].ob_state) weck = 0;
else weck = 1;
}
}
} /* das ist alles */